package com.study.webapp.leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;

/**
 * 两数之和
 */
public class Leet_001 {

	public static void main(String[] args) {
		int[] nums = { 2, 7, 13, 15 };
		int[] list = getTarget(nums, 9);
		System.out.println(JSON.toJSONString(list));
	}

	public static int[] getTarget(int[] nums, int target) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i< nums.length; i++) {
			int a = target - nums[i];
			if (map.containsKey(a)) {
				return new int[] {map.get(a),i};
			}
			map.put(nums[i],i);
		}
		throw new RuntimeException("");
	}

}
